import { IFeidaoAiWeappPage } from '@dfeidao/atom-wxapp/interfaces';
import nodejs from '@dfeidao/atom-wxapp/msg/nodejs';
import set_local from '@dfeidao/atom-wxapp/local/set';
import get_local from '@dfeidao/atom-wxapp/local/get';
import render from '@dfeidao/atom-wxapp/render/render';
import stop_pull_down from '@dfeidao/atom-wxapp/api/interaction/stop-pull-down-refresh';
import show_toast from '@dfeidao/atom-wxapp/api/interaction/show-toast';

export default async function a005(fd: IFeidaoAiWeappPage) {
	const flag = get_local(fd, 'flag');
	console.log(flag)

	if (flag === '0') {
		try {
			const page_size = 20;
			const data = await nodejs<{ datas: any[] }>('app-equipment-find', {
				asc: ['equip_no'],
				page_size,
				page_no: 1
			}) as any;

			if (data.length > 0) {

				set_local(fd, 'data', data)
				render(fd, { data })
				stop_pull_down();
			} else {
				show_toast('没有更多数据了', 'none');
				stop_pull_down();
			}

		} catch (error) {
			stop_pull_down();
			console.warn(error);
		}


	} else {

		try {
			const data = await nodejs('app-lack_merchandis_shelves-find', {
				sort: { equip_no: 1 },
				page_no: 1,
				page_size: 1,
				filter: {
					product_up_status: "已上架"
				}
			}) as any;

			if (data.length > 0) {
				set_local(fd, 'data', data)
				render(fd, { data })
				stop_pull_down();
			} else {
				show_toast('没有更多数据了', 'none');
				stop_pull_down();
			}

		} catch (error) {
			stop_pull_down();
			console.warn(error);
		}

	}
}
